package com.example.card.abstracttransactions;

import cn.hutool.core.util.RandomUtil;
import com.example.card.domain.card.Card;
import com.example.card.CardConstant;
import com.example.card.CardDataBase;
import com.example.card.Transaction;
import com.example.card.domain.card.CardClassification;
import com.example.card.domain.card.ExpireDataLimit;

public abstract class AddCardTransaction implements Transaction {
    public int id;
    public String name;
    public int balance;
    //0b1充值， 0b10储油码储油，0b100油票购油，0b1000V油抵扣 0b10000


    public AddCardTransaction(int id, int balance) {
        this.id = id;
        this.balance = balance;
    }

    public abstract int getCardFunction();

    public   abstract int getCardOilLabel();

    public  abstract String getCardName();

    public   abstract String getCardNoPrefix();

    public  abstract Integer getType();

    public    abstract CardClassification getCardClassification();
    public   abstract ExpireDataLimit getExpireDataLimit();


    @Override
    public void execute() {
        Card card = new Card(id, getCardName(), randomCardNo(getCardNoPrefix()), CardConstant.STATUS_INIT, balance
                , getType(), getCardOilLabel(), getCardFunction());
        card.setCardClassification(getCardClassification());

        card.setExpireDataLimit(getExpireDataLimit());

        CardDataBase.addCard(card);
    }

    private String randomCardNo(String prefix) {
        long l = RandomUtil.randomLong(2111_1111_1111L, 9999_9999_9999L);
        return prefix + l;
    }
}
